package oop.ex3.crosswords;

/**
 * A class that represents a slot to set a crossword entry.<br>
 * First all slots are empty and then CrosswordEntries are set in horizontal and vertical direction
 * 
 * @author tsachiho
 * @author kobi_atiya
 * 
 */

public class MyCrosswordSlot {
    private CrosswordEntry horEntry;         // horizontal entry
    private CrosswordEntry verEntry;         // vertical entry

    private int            horChars;         // horizontal empty chars
    private int            verChars;         // vertical empty chars

    protected final char   EMPTY_SPACE = '_';

    /**
     * A constructor for the MyCrosswordSlot class
     * 
     * @param x the x position of the CrosswordEntry
     * @param y the y position of the CrosswordEntry
     * @param verSpace number of vertical space to allocate
     * @param horSpace number of horizontal space to allocate
     */
    public MyCrosswordSlot(int x, int y, int verSpace, int horSpace) {
        horEntry = new MyCrosswordEntry(new MyCrosswordPosition(x, y, false));
        verEntry = new MyCrosswordEntry(new MyCrosswordPosition(x, y, true));

        horChars = horSpace;
        verChars = verSpace;
    }

    /**
     * A copy constructor
     * 
     * @param other the instance to copy from
     */

    public MyCrosswordSlot(MyCrosswordSlot other) {
        this.horEntry = other.horEntry;
        this.verEntry = other.verEntry;
        this.horChars = other.horChars;
        this.verChars = other.verChars;
    }

    /**
     * Get the Crossword entry which is set in the given direction
     * 
     * @param dir an Enum representing the direction
     * @return the crossword entry object
     */
    public CrosswordEntry getEntry(Direction dir) {
        switch (dir) {
            case HORIZONTAL:
                return horEntry;

            case VERTICAL:
                return verEntry;
        }
        return null;
    }

    /**
     * Sets the given CrosswordEntry, The direction is set according to the direction of the given value
     * 
     * @param value the CrosswordEntry to set
     */
    public void setEntry(CrosswordEntry value) {
        if (value.getPosition().isVertical()) verEntry = value;
        else horEntry = value;
    }

    /**
     * Gets the size of this slot in the given direction
     * 
     * @param dir an Enum representing the direction
     * @return the size of this slot in the given direction
     */
    public int getSlotSize(Direction dir) {
        switch (dir) {
            case HORIZONTAL:
                return horChars;

            case VERTICAL:
                return verChars;
        }
        return -1;
    }

    @Override
    public String toString() {
        return (horEntry.getPosition().toString() + horChars + "\n" + verEntry.getPosition().toString() + verChars);
    }
}
